<?php
namespace app\components;
/**
 * Created by PhpStorm.
 * @author: lizhi <lizhi7@xin.com>
 * Date: 2018/4/3 19:25
 */
class Calculation
{
    /**
     * @author lizhi7  <lizhi7@xin.com>
     * @param $proArr
     * @return int|string
     */
    public static function get_rand($proArr) {
        $result = '';
        //概率数组的总概率精度
        $proSum = array_sum($proArr);
        //概率数组循环
        foreach ($proArr as $key => $proCur) {
            $randNum = mt_rand(1, $proSum);       //抽取随机数
            if ($randNum <= $proCur) {
                $result = $key;             //得出结果
                break;
            } else {
                $proSum -= $proCur;
            }
        }
        unset ($proArr);
        return $result;
    }
}